{% extends 'warehouse/base.html' %}

{% block title %}仓库管理系统 - 仪表盘{% endblock %}

{% block content %}
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <h1 class="mb-4">仓库管理系统</h1>
            <p class="mb-4">欢迎使用仓库管理系统，{{ user.username }}！</p>
        </div>
    </div>

    {% if messages %}
        {% for message in messages %}
            <div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
                {{ message }}
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            </div>
        {% endfor %}
    {% endif %}

    <div class="row">
        <!-- 左侧功能导航 -->
        <div class="col-lg-3 mb-4">
            <div class="card">
                <div class="card-header">
                    <h3>功能导航</h3>
                </div>
                <div class="card-body">
                    <div class="list-group">
                        {% if 'goods_read' in user_permissions %}
                            <a href="{% url 'warehouse:goods_list' %}" class="list-group-item list-group-item-action">
                                <i class="fas fa-box"></i> 商品管理
                            </a>
                        {% endif %}

                        {% if 'goods_create' in user_permissions %}
                            <a href="{% url 'warehouse:goods_create' %}" class="list-group-item list-group-item-action">
                                <i class="fas fa-plus-circle"></i> 创建商品
                            </a>
                        {% endif %}
                        
                        {% if 'inbound_create' in user_permissions %}
                            <a href="{% url 'warehouse:inbound_create' %}" class="list-group-item list-group-item-action">
                                <i class="fas fa-arrow-down"></i> 入库操作
                            </a>
                        {% endif %}
                        
                        {% if 'outbound_create' in user_permissions %}
                            <a href="{% url 'warehouse:outbound_create' %}" class="list-group-item list-group-item-action">
                                <i class="fas fa-arrow-up"></i> 出库操作
                            </a>
                        {% endif %}
                        
                        {% if 'inventory_create' in user_permissions %}
                            <a href="{% url 'warehouse:inventory_create' %}" class="list-group-item list-group-item-action">
                                <i class="fas fa-clipboard-check"></i> 库存盘点
                            </a>
                        {% endif %}
                        
                        {% if 'finance_read' in user_permissions %}
                            <a href="{% url 'warehouse:wage_list' %}" class="list-group-item list-group-item-action">
                                <i class="fas fa-money-bill-wave"></i> 工资管理
                            </a>
                        {% endif %}
                        
                        {% if 'goods_read' in user_permissions %}
                            <a href="{% url 'warehouse:inbound_list' %}" class="list-group-item list-group-item-action">
                                <i class="fas fa-list"></i> 入库记录
                            </a>
                            
                            <a href="{% url 'warehouse:outbound_list' %}" class="list-group-item list-group-item-action">
                                <i class="fas fa-list"></i> 出库记录
                            </a>
                            
                            <a href="{% url 'warehouse:inventory_list' %}" class="list-group-item list-group-item-action">
                                <i class="fas fa-list"></i> 盘点记录
                            </a>
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>

        <!-- 右侧内容区域 -->
        <div class="col-lg-9">
            <!-- 仓库基础数据统计 -->
            <div class="row mb-4">
                <div class="col-md-3 mb-3">
                    <div class="card text-white bg-primary h-100">
                        <div class="card-body text-center">
                            <h5 class="card-title">商品总数</h5>
                            <h2>{{ total_goods }}</h2>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 mb-3">
                    <div class="card text-white bg-success h-100">
                        <div class="card-body text-center">
                            <h5 class="card-title">库存总量</h5>
                            <h2>{{ total_stock }}</h2>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 mb-3">
                    <div class="card text-white bg-info h-100">
                        <div class="card-body text-center">
                            <h5 class="card-title">今日入库</h5>
                            <h2>{{ today_inbound }}</h2>
                            <small>{{ today_inbound_count }} 条记录</small>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 mb-3">
                    <div class="card text-white bg-warning h-100">
                        <div class="card-body text-center">
                            <h5 class="card-title">今日出库</h5>
                            <h2>{{ today_outbound }}</h2>
                            <small>{{ today_outbound_count }} 条记录</small>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 系统状态 -->
            <div class="row mb-4">
                <div class="col-12">
                    <div class="card">
                        <div class="card-header">
                            <h3>系统状态</h3>
                        </div>
                        <div class="card-body">
                            <p><strong>数据库状态:</strong> {{ db_status }}</p>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 最近操作记录 -->
            <div class="row">
                <div class="col-12">
                    <div class="card">
                        <div class="card-header">
                            <h3>最近操作记录</h3>
                        </div>
                        <div class="card-body">
                            <div class="table-responsive">
                                <table class="table table-striped">
                                    <thead>
                                        <tr>
                                            <th>操作类型</th>
                                            <th>商品</th>
                                            <th>数量</th>
                                            <th>操作员</th>
                                            <th>操作时间</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        {% for operation in recent_operations %}
                                        <tr>
                                            <td>
                                                {% if operation.type == '入库' %}
                                                    <span class="badge bg-info">入库</span>
                                                {% elif operation.type == '出库' %}
                                                    <span class="badge bg-warning">出库</span>
                                                {% endif %}
                                            </td>
                                            <td>{{ operation.goods }}</td>
                                            <td>{{ operation.quantity }}</td>
                                            <td>{{ operation.operator }}</td>
                                            <td>{{ operation.time|date:"Y-m-d H:i" }}</td>
                                        </tr>
                                        {% empty %}
                                        <tr>
                                            <td colspan="5">暂无操作记录</td>
                                        </tr>
                                        {% endfor %}
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}